﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace CustomIndexerSample
{
    public class PersonCollection
    {
        private Person[] _people;

        public PersonCollection(params Person[] people)
        {
            _people = people.ToArray();
        }
        //自定义索引运算符
        public Person this[int index]
        {
            get { return _people[index]; }
            set { _people[index] = value; }
        }
        //利用枚举类型返回_people中生日相同的多个Person对象
        //where方法在名称空间System.Linq中定义
        public IEnumerable<Person> this[DateTime birthDay] => _people.Where(p => p.Birthday == birthDay);

    }
}